package com.ellricky.baselib.adapter.course

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.ellricky.baselib.R
import com.ellricky.baselib.entity.IdNameEntity

class CourseAgeAdapter(context: Context) :
    BaseRecyclerAdapter<IdNameEntity>(R.layout.base_item_course_age) {

    private val mTempColor = arrayOf(
        "#C0E4E8", "#A2D7DE", "#9ED8F0", "#8BC1EA", "#83A2D3", "#688AAC", "#018699",
        "#02A3B1", "#2983A5", "#59B8C8", "#0095C5", "#4C6BA9", "#BDBBE2", "#887AAA", "#4C5AB0"
    )

    override fun onBindViewHolder(holder: SmartViewHolder?, entity: IdNameEntity?, position: Int) {
        holder?.text(R.id.tvName, entity?.name)
        holder?.text(R.id.tvAge, "${entity?.age}岁")
        val shapeDrawable = holder?.itemView?.background
                as GradientDrawable
        shapeDrawable.setColor(Color.parseColor(getBackgroundColor()))
    }

    private fun getBackgroundColor(): String {
        return mTempColor[(Math.random() * 10 + 5).toInt()]
    }
}